package mjc.egg;
import mjc.tds.*;
import mjc.type.*;
import mjc.gc.*;
import mjc.compiler.*;
import java.util.*;
import mg.egg.eggc.compiler.libjava.lex.*;
import mg.egg.eggc.compiler.libjava.*;
import mg.egg.eggc.compiler.libjava.problem.IProblem;
import java.util.Vector;
import java.util.List;
import java.util.ArrayList;
public class S_PROGRAMME_MJAVA implements IDstNode {
LEX_MJAVA scanner;
  S_PROGRAMME_MJAVA() {
    }
  S_PROGRAMME_MJAVA(LEX_MJAVA scanner) {
    this.scanner = scanner;
    offset = 0;
    length = 0;
    this.att_scanner = scanner;
    }
int [] sync= new int[0];
  MJAVASourceFile att_source;
  LEX_MJAVA att_scanner;
  TAM glob_0_machineTAM;
  AbstractMachine glob_0_machine;
  private void regle0() throws Exception {
 offset = scanner.getOffset(0);

    //declaration
    S_IMPORTS_MJAVA x_4 = new S_IMPORTS_MJAVA(scanner) ;
    S_DEFCLASSE_MJAVA x_6 = new S_DEFCLASSE_MJAVA(scanner) ;
    //appel
      action_init_0(x_4, x_6);
      action_cpu_0(x_4, x_6);
    x_4.analyser() ;
      addChild(x_4);
      action_tds_0(x_4, x_6);
    x_6.analyser() ;
      addChild(x_6);
      action_gen_0(x_4, x_6);
     length =x_6.getOffset() + x_6.getLength()  -offset;
  }
private void action_init_0(S_IMPORTS_MJAVA x_4, S_DEFCLASSE_MJAVA x_6) throws Exception {
try {
// locales
// instructions
glob_0_machine=this.att_source.getMachine();
if (glob_0_machine instanceof TAM ){
glob_0_machineTAM=((TAM)glob_0_machine);
}

}catch(RuntimeException e) {		//e.printStackTrace();
	}
  }
private void action_cpu_0(S_IMPORTS_MJAVA x_4, S_DEFCLASSE_MJAVA x_6) throws Exception {
try {
// instructions
x_4.att_cpu=glob_0_machineTAM;
x_6.att_cpu=glob_0_machineTAM;
}catch(RuntimeException e) {		//e.printStackTrace();
	}
  }
private void action_gen_0(S_IMPORTS_MJAVA x_4, S_DEFCLASSE_MJAVA x_6) throws Exception {
try {
// locales
String loc_src;
// instructions
loc_src=x_4.att_code+x_6.att_code+glob_0_machineTAM.genFin();
    glob_0_machineTAM.writeCode(this.att_source.getFileName(), loc_src);
}catch(RuntimeException e) {		//e.printStackTrace();
	}
  }
private void action_tds_0(S_IMPORTS_MJAVA x_4, S_DEFCLASSE_MJAVA x_6) throws Exception {
try {
// instructions
x_6.att_tdsi=x_4.att_tdsii;
x_6.att_tds= new TDS("");
x_6.att_dep=0;
}catch(RuntimeException e) {		//e.printStackTrace();
	}
  }
  public void analyser () throws Exception {
    scanner.lit ( 1 ) ;
    switch ( scanner.fenetre[0].code ) {
      case LEX_MJAVA.token_import : // 45445
        regle0 () ;
      break ;
      case LEX_MJAVA.token_classe : // 45462
        regle0 () ;
      break ;
      default :
               scanner._interrompre(IProblem.Syntax, scanner.getBeginLine(), IMJAVAMessages.id_MJAVA_unexpected_token,MJAVAMessages.MJAVA_unexpected_token,new String[]{scanner.fenetre[0].getNom()});
    }
  }
    private IDstNode parent;
    public void setParent( IDstNode p){parent = p;}
    public IDstNode getParent(){return parent;}
    private List<IDstNode> children = null ;
    public void addChild(IDstNode node){
      if (children == null) {
         children = new ArrayList<IDstNode>() ;}
      children.add(node);
      node.setParent(this);
    }
    public List<IDstNode> getChildren(){return children;}
    public boolean isLeaf(){return children == null;}
    public void accept(IDstVisitor visitor) {
      boolean visitChildren = visitor.visit(this);
      if (visitChildren && children != null){
        for(IDstNode node : children){
          node.accept(visitor);
        }
    }
    visitor.endVisit(this);
  }
  private int offset;
  private int length;
  public int getOffset(){return offset;}
  public void setOffset(int o){offset = o;}
  public int getLength(){return length;}
  public void setLength(int l){length = l;}
  private boolean malformed = false;
  public void setMalformed(){malformed = true;}
  public boolean isMalformed(){return malformed;}
  }
